<?php 
$id				= gpc_getIntPost("id",$id);
$name			= gpc_getStringPost("Name");
$urlstring		= gpc_getStringPost("URL",$name);
$Code			= gpc_getStringPost("Code");
$Tag 			= gpc_getStringPost("Tag");
$category 		= gpc_getIntPost("Category");
$Trade	 		= gpc_getIntPost("Trade");
$order			= gpc_getIntPost("Order");
$TopBottomOrder	= gpc_getIntPost("TopBottomOrder");  
$status			= gpc_getIntPost("Status");

$isNew          = gpc_getIntPost('isNew');
$isHot          = gpc_getIntPost('isHot');


$Warranty		= gpc_getStringPost("Warranty");
$Promotion		= gpc_getStringPost("Promotion");
$Depository		= gpc_getIntPost("Depository");
$Price			= gpc_getFloatPost("Price");
$PriceOld		= gpc_getFloatPost("PriceOld");
$Description 	= gpc_getStringPost("Description");
$Content		= gpc_getStringPost("Content");

$property		= getPropertyUpload($category);
$filters		= gpc_getStringArray("filters");

$metatitle		= gpc_getStringPost("MetaTitle",$title);
$metakeywords	= gpc_getStringPost("MetaKeywords");
$metadescription= gpc_getStringPost("MetaDescription");

$ImgIntro 		= gpc_getStringPost('ImgIntro');
$ImgBanner 		= gpc_getStringPost('ImgBanner');
$ImgBackground	= gpc_getStringPost('ImgBackground');


//check form:
$urlstring      = Trim_Url($urlstring); 
CheckUrlString($urlstring,"tblproduct",$category);

if($category==0)
{
	error_transfer("Please select Category");
}else if(empty($name))
{
	error_transfer("Please enter Name");
}

$order          = GetOrderForInsert($TopBottomOrder,$order,$category,"tblproduct");

$Description	= replace_pathlocal($Description);
$Content		= replace_pathlocal($Content);
	
if($act=='insert')
{
    $postdate   = datePost();
	$poster     = getUserNamePost();		

	$sql_insert = "INSERT INTO tblproduct
		(iParentId,cUrlString,cCode,cName,cImage,cBanner,cDescription,cContent,cProperty,
		cWarranty,cPromotion,iDepository,cPrice,cPriceOld,iTradeId,iNew,iHot,
		iStatus,iOrder,iCountView,cMetaTitle,cMetaDescription,cMetaKeywords,cPoster,dPostDate,cLanguage) 
	VALUES 
		($category,'$urlstring','$Code','$name','$ImgIntro', '$ImgBanner','$Description','$Content','$property',
		'$Warranty','$Promotion','$Depository','$Price','$PriceOld','$Trade','$isNew','$isHot',
		'$status',$order,0,'$metatitle','$metadescription','$metakeywords','$poster','$postdate','$language')";

	$dbsql->query($sql_insert);
    $id        = $dbsql->insert_id();
    
}else if($id>0)
{
    $sql_update = "UPDATE tblproduct SET
				iParentId	 	= $category,
				cUrlString		= '$urlstring',
				cCode			= '$Code',
				cName 			= '$name',
				cImage 			= '$ImgIntro',
				cBanner 		= '$ImgBanner',
				cDescription	= '$Description',
				cContent 		= '$Content',
				cProperty		= '$property',
				cWarranty		= '$Warranty',
				cPromotion		= '$Promotion',
				iDepository		= '$Depository',
				cPrice			= '$Price',
				cPriceOld		= '$PriceOld',
				iTradeId		= '$Trade',
				iStatus 		= '$status',	
                iNew            = '$isNew',
                iHot            = '$isHot',       	
				cMetaTitle 		= '$metatitle',
				cMetaDescription= '$metadescription',
				cMetaKeywords 	= '$metakeywords' 
				WHERE iId= $id";
	
	$dbsql->query($sql_update);
    
    Insert_Tracking("edit Product : $name");
}

Update_FiltersProduct($filters,$id);

$msg = "Update Product Success !";
page_transfer($msg,getUrlBack());
?>
